$(function () {
    var nav = [];
    $(".item-box").each(function () {
        nav.push({
            title: $(this).find(".item-title").text(),
            price: $(this).find(".item-price").text(),
            alt: $(this).find("img").attr("alt"),
            path: $(this).find("img").attr("src"),
            type: $(this).find(".item-ribbon").text()
        })

    });


    var pro = [{
            "title": "Battery for Sony VGP-BPS37",
            "price": "RM 205.33",
            "alt": "Sony VGP-BPS37 Battery",
            "path": "./images/VGP-BPS37.jpg",
            "type": "Hot"
        }, {
            "title": "Battery for Asus U32U",
            "price": "RM 138.67",
            "alt": "Asus U32U Battery",
            "path": "./images/A42-U36-8cell.jpg",
            "type": "Hot"
        }, {
            "title": "Battery for Dell 357F9",
            "price": "RM 192.00",
            "alt": "Dell 357F9 Battery",
            "path": "./images/357F9.jpg",
            "type": "Hot"
        }, {
            "title": "Battery for Apple A1322",
            "price": "RM 185.33",
            "alt": "Apple A1322 Battery",
            "path": "./images/A1322.jpg",
            "type": "Hot"
        }, {
            "title": "Battery for Acer Aspire V5-473PG",
            "price": "RM 155.33",
            "alt": "Acer Aspire V5-473PG Battery",
            "path": "./images/AP13B3K.jpg",
            "type": "Hot"
        }, {
            "title": "Battery for Asus X453",
            "price": "RM 162.00",
            "alt": "Asus X453 Battery",
            "path": "./images/X453-2cell.jpg",
            "type": "Hot"
        }, {
            "title": "Battery for Dell XPS 15-9550-D1828T",
            "price": "RM 198.67",
            "alt": "Dell XPS 15-9550-D1828T Battery",
            "path": "./images/Precision5510-3cell.jpg",
            "type": "Hot"
        }, {
            "title": "Battery for HP JC04",
            "price": "RM 162.00",
            "alt": "HP JC04 Battery",
            "path": "./images/JC04.jpg",
            "type": "Hot"
        }, {
            "title": "Battery for Apple A1382",
            "price": "RM 185.33",
            "alt": "Apple A1382 Battery",
            "path": "./images/A1382.jpg",
            "type": "RCMD"
        }, {
            "title": "Battery for HP CA06XL",
            "price": "RM 132.00",
            "alt": "HP CA06XL Battery",
            "path": "./images/CA06-6cell.jpg",
            "type": "RCMD"
        }, {
            "title": "Battery for Sony VGP-BPS2C",
            "price": "RM 184.81",
            "alt": "Sony VGP-BPS2C Battery",
            "path": "./images/VGP-BPS2-6cell-black-original.jpg",
            "type": "RCMD"
        }, {
            "title": "Battery for Samsung NP730U3E-X02",
            "price": "RM 185.33",
            "alt": "Samsung NP730U3E-X02 Battery",
            "path": "./images/PBWN4AB.jpg",
            "type": "RCMD"
        }, {
            "title": "Battery for Toshiba Satellite L55W-C5252",
            "price": "RM 168.67",
            "alt": "Toshiba Satellite L55W-C5252 Battery",
            "path": "./images/PA5208U-1BRS.jpg",
            "type": "RCMD"
        }, {
            "title": "\tBattery for Fujitsu LifeBook AH532/GFX",
            "price": "\tRM 168.67",
            "alt": "Fujitsu LifeBook AH532/GFX Battery",
            "path": "./images/AH532.jpg",
            "type": "RCMD"
        }, {
            "title": "Battery for Dell JD25G",
            "price": "RM 185.33",
            "alt": "Dell JD25G Battery",
            "path": "./images/XPS139350.jpg",
            "type": "RCMD"
        }, {
            "title": "Battery for HP Pavilion 15-BA053NR",
            "price": "RM 135.33",
            "alt": "HP Pavilion 15-BA053NR Battery",
            "path": "./images/HS04.jpg",
            "type": "RCMD"
        }],
        typeList = ["Hot", "RCMD"];

    function getProductList(pro) {
        var struck = [];
        for (var i = 0; i < pro.length; i++) {
            var p = pro[i];
            struck.push("<div class='item-box cbp-item " + p.type + "'><a href='https://www.laptopbattery.com.my/dell-batteries/dell-jd25g-battery.htm'><div class='item-ribbon'><span>" + p.type + "</span></div><div class='item-image'><img src='" + p.path + "' alt='" + p.alt + "'></div><div class='item-title'><h3>" + p.title + "</h3></div><div class='item-price float-r'><em>" + p.price + "</em></div></a></div>");
            if ($.inArray(p.type, typeList) == -1) {
                typeList.push(p.type);
            }
        }
        return struck.join("");
    }

    function getTypeList(tp) {
        var tt = ['<li class="list-inline-item cbp-filter-item u-cubeportfolio__item" data-filter="*">All</li>'];
        for (var i = 0; i < tp.length; i++) {
            var ti = tp[i];
            tt.push('<li class="list-inline-item cbp-filter-item u-cubeportfolio__item" data-filter=".' + ti + '">' + ti + '</li>')
        }
        return tt.join("");
    }
    $("#filterControls").html(getTypeList(typeList));
    $("#ProductCbp").html(getProductList(pro)).cubeportfolio({
        layoutMode: "grid",
        animationType: "quicksand",
        filterDeeplinking: true,

        gapHorizontal: 30,
        gapVertical: 30,
        caption: 'overlayBottomAlong',
        mediaQueries: [{
            "width": 1500,
            "cols": 4
        }, {
            "width": 1100,
            "cols": 4
        }, {
            "width": 800,
            "cols": 3
        }, {
            "width": 480,
            "cols": 2
        }, {
            "width": 300,
            "cols": 1
        }],
        filters: $("#filterControls"),
    });
});